#ifndef NODE_H
#define NODE_H

#include "d3dUtil.h"
#include "VertexFormat.h"

class Node
{
public:
	Node(ID3D10Device*	device ,std::string name);
	Node(std::string name);
	virtual ~Node(void);

	virtual void Draw();
	virtual void Update();

	void SetBuffer();
	void SetDevice(ID3D10Device*	device);
	void SetVertexBuffer(ID3D10Buffer*	buffer ,DWORD numVertex);
	void SetIndexBuffer	(ID3D10Buffer*	buffer ,DWORD numIndex);

	//set the visibility
	void SetVisible(bool visible);

	void SetWorldPosition(const D3DXVECTOR3& pos);
	void SetOrientation(const D3DXVECTOR3& orien);
	void SetScaleFactor(const D3DXVECTOR3& scale);
	void SetUpVector(const D3DXVECTOR3& up);

	//texture method
	void AttachTexture(ID3D10ShaderResourceView*	texResView);
	ID3D10ShaderResourceView* GetAttachTexture();

	//child node method
	virtual void AddChildNode(Node* child);
	virtual void SetParentNode(Node* parent);

	D3DXMATRIX	GetWorldMatrix();
	D3DXMATRIX	GetTextureMatrix();
	
	D3DXVECTOR3	GetPosition();

	//set the visibility
	bool IsVisible();

	//rotate
	void pitch(float angle);
	void roll(float angle);
	void yaw(float angle);
	void rotateY(float angle);


	//use for test 
	void SetWorldMatrix(const D3DXMATRIX& mat);

protected:

	void UpdateWorldMatrix();



	//Device,Vertex and Index Buffer
	ID3D10Device*				m_pDevice;
	std::string					m_nodeName;
	ID3D10Buffer*				m_pVB;
	ID3D10Buffer*				m_pIB;

	DWORD						m_iNumVertices;
	DWORD						m_iNumIndices;
	DWORD						m_iNumFaces;
	bool						m_bVisible;

	//world position and orientation
	D3DXVECTOR3					m_vPostion;
	D3DXVECTOR3					m_vOrientation;
	D3DXVECTOR3					m_vScale;

	D3DXVECTOR3					m_vUp;
	D3DXVECTOR3					m_vRight;

	//Node Variable
	D3DXMATRIX					m_matWorld;
	D3DXMATRIX					m_matTexMtx;

	//attach texture
	ID3D10ShaderResourceView*	m_pTextureMapRV;

	//child node list
	std::list<Node*>			m_childNodeList;
	Node*						m_parentNode;
};

#endif